package fr.umlv.escapeir.painters;

import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;

import fr.umlv.escapeir.game.Behavior;

public class Scene extends AnimatedLayer {
	
	private final List<Layer> layers;
	private final ArrayList<AnimatedLayer> mlayers;
	private final Behavior behavior;
	
	public Scene () {
		this.layers = new ArrayList<>();
		this.mlayers = new ArrayList<>();
		this.behavior = new Behavior() {
			@Override
			public void apply() {
				for (AnimatedLayer ml : mlayers)
					ml.apply();
			}
		};
	}
	
	public void addLayer(Layer layer) {
		layers.add(layer);
	}
	public void addLayer(AnimatedLayer layer) {
		mlayers.add(layer);
		layers.add(layer);
	}
	
	public void removeLayer(Layer layer) {
		layers.remove(layer);
	}
	
	public void clear() {
		layers.clear();
	}

	@Override
	public void render(Graphics2D painter) {
		for (Layer l : layers) {
			l.render(painter);
		}
	}

	@Override
	public void apply() {
		behavior.apply();
	}
}
